package com.dd.mytest.plugins;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.util.Properties;

/**
 * @author: lkd
 * @date: 2023/05/12/18:09
 * @Description:
 */
@Intercepts(
  {
    @Signature(
      type = Executor.class,
      method = "query",
      args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}
    )
  }
)
public class MyInterceptor implements Interceptor {


  /**
   * invocation 封装了拦截的类，方法，方法参数
   */
  @Override
  public Object intercept(Invocation invocation) throws Throwable {

    // 目标方法执行
    Object res = invocation.proceed();

    return res;
  }

  /**
   * 返回一个JDK代理对象
   */
  @Override
  public Object plugin(Object target) {
    return Interceptor.super.plugin(target);
  }

  /**
   * 允许在配置文件中配置一些属性即
   * < plugin interceptor="">
   * < property name ="" value =""/>
   * < /plugin>
   */
  @Override
  public void setProperties(Properties properties) {
    System.out.println(properties);
  }
}
